/**
 * 功能描述 列表
 */
define(function (require, exports, module) {
	var Grid = require("grid"); 	
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");	
	
	var intentionregister_Props = require("../constant/returnvisit_Props");
	var intentionRegisterGrid_Events = require("../handler/ReturnvisitGrid_Events");//ReturnvisitGrid_Events

    var instance = {
        initComponent: function (params, widget) {
        	var grid = new Grid({
        		autoRender:false,
                parentNode : ".J-grid",
                url : "api/customer/queryall",
                params : function(){
                		var obj={
                				"productType.product":widget.get("subnav").getValue("product"),
                				"productType":widget.get("subnav").getValue("productType"),
                				"intention":widget.get("subnav").getValue("intention"),
                				"saleConsultant":activeUser.pkUser,
                				"dataSource": "Visit",
                				"status":widget.get("subnav").getValue("status"),
                				"returnVisitTime":widget.get("subnav").getValue("visitTime").start,
                				"returnVisitTimeEnd":widget.get("subnav").getValue("visitTime").end,
                				"orderString":"returnVisitTime:desc",
    	     					fetchProperties:intentionregister_Props.gridFetchProperties
                		}
                		return obj;
                },
                model : {
                    columns : [{
                        name : "personalInfo.name",
                        label : "姓名",
                        format : "detail",
						formatparams : {
							key: "detail",
							handler : function(index,data,rowEle){
								intentionRegisterGrid_Events.showReturnRecord(widget, data, function(datas){
									if(!data.returnVisitCount){
										intentionRegisterGrid_Events.showDetail(widget,data,true);
									}else{
										var detailData = intentionRegisterGrid_Events.compareVisitDate(data, datas);
										intentionRegisterGrid_Events.recordEdit(widget,detailData,true);
									}
								});
							}
						}
                    },{
                        name : "personalInfo.mobilePhone",
                        label : "联系电话",
                    },{
                        name : "productType.product.name",
                        label : "产品",
                    },{
                        name : "productType.name",
                        label : "产品类型",
                    },{
                        name : "intention.value",
                        label : "意向",
                    },{
                        name : "status.value",
                        label : "状态",
                    },{
                        name : "returnVisitCount",
                        label : "回访次数",
                        format : "detail",
						formatparams : {
							key: "returnCord",
							handler : function(index,data,rowEle){
								if(!data.returnVisitCount){
									Dialog.alert({
										tip : "提示",
										content : "该客户暂无回访记录"
									})
								}else{
									intentionRegisterGrid_Events.showReturnRecord(widget, data, function(datas){
										
										widget.get("recordgrid").setData(datas);
										widget.get("subnav").hide(["visitTime","status","intention","productType","product","search","save"]).show(["return"]);
										widget.show([".J-recordgrid"]).hide([".J-grid"]);
//										widget.get("recordgrid").setData(datas);
									});
								}
							}
						}
                    },{
                        name : "returnVisitTime",
                        label : "最新回访时间",
                        format:"date",
						formatparams:{
					    	mode:"YYYY-MM-DD HH:mm"
					    }
                    },{
                        name : "saleConsultant.name",
                        label : "销售顾问",
                    },{
                        name : "show",
                        label : "操作",
    					format:"button",
						formatparams:[{
							id:"visit",
							text:"回访",
							handler:function(index,data,rowEle){
								intentionRegisterGrid_Events.showDetail(widget,data,false,"Return");
							}
						}]
                    }]
                }
            });
        	widget.set("grid",grid);
        }
    };
    module.exports = instance;
});
